﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BasicFrame.WebControls;
using flsfragusseModel;





class Contractinformation
{
   public string afNamn;
   public string SalesNamn;
   public string kundnamn;
   public string contractnr;
   public string orgnrorpersnr;
   public string telefonnummer;
   public string adress;
   public string By;
   public string legitimation;
   public DateTime leveransdag;
   public string bilmarke;
   public string bilmodell;
   public string chassinr;
   public string regnr;
   public DateTime regdag;
   public DateTime contractstart;
   public string meterreadingcontractstart;
   public string meterreadingcontractend;
   public DateTime contractstop;
   public string calculatedYearlydriving;
   public string contracttotaldriven;
   public string monthpayment;
   public string invoicecost;
   public DateTime duedate;
   public string contractlength;
   public string paymentfrequence;
   public string signort;
   public DateTime signdate;
}
public enum modeUser
{
    SALESMEN = 1,
    ADMINISTRATOR
}
public partial class partner_controls_viewContracts : System.Web.UI.UserControl
{
    bool filldata = false;
  
   
   //mode salesmen=1,admin=2,
    public int mode =-1;

    public int partnerid = 7;
    public int productid = 20;
    //f
    public int countryID = 3;
    public int gvehicleID = 0;
    public string countryCurrency = string.Empty;
    string pricelistCategory = "n1";
    string invoiceFee = string.Empty;
    string test = "";
    public void Start()
    {
        if (!IsPostBack)
        {

          lblreferer.Text= Request.UrlReferrer.PathAndQuery.ToString();
            Fillcombos();
            EnableDisableButtons();

          
        }


    }

    private void EnableDisableButtons()
    {
        //admin
        //if (mode == Convert.ToInt32(modeUser.ADMINISTRATOR))
        //{
        //    btnApprove.Visible = true;
        //    btnDissaprove.Visible = true;

          
        //}
        if (mode == Convert.ToInt32(modeUser.SALESMEN))
        {
            lblQuerystring.Text = Convert.ToInt32(Request.QueryString["vehicleID"]).ToString();
            FillVehicle(Convert.ToInt32(Request.QueryString["vehicleID"]));
           // FillVehicle(4662);
            btnSpara.Visible = true;
            btnTerminate.Visible = true;
        }
    }

    private void GetCouuntryCurrency()
    {

        flsfragusseEntities1 cEntity = new flsfragusseEntities1();
         var result = from p in cEntity.tblCountry
                      where p.countryID == countryID
                      select new { Currency = p.countryCurrency };
         foreach (var rec in result)
         {
             countryCurrency=Convert.ToString(rec.Currency);
         }
    }

    private void GetinvoiceFeeForPartner()
    {
        flsfragusseEntities1 cEntity = new flsfragusseEntities1();
        var result = from p in cEntity.tblPartner
                     where p.partnerID==partnerid
                     select new { fee=p.invoiceFee };
        foreach (var rec in result)
        {
            
            invoiceFee =Convert.ToString(rec.fee);
        }
    }
    private void FillVehicle(int vehicleID)
    {

        flsfragusseEntities1 cEntity = new flsfragusseEntities1();
        var vehicle = from p in cEntity.tblVehicle
                      where p.vehicleID == vehicleID
                      select p;

                              //   new { Name = p.brand, ID = p.brandID };

        //fillvalues
        foreach (var vec in vehicle)
        {

            vehicleID = vec.vehicleID;
          drpCarBrand.SelectedValue=Convert.ToString(vec.brandID);
          drpModell.SelectedValue = Convert.ToString(vec.modelID);
          drpFueltype.SelectedValue = Convert.ToString(vec.isDieselcar);
          drpCylinderVolume.SelectedValue=Convert.ToString(vec.cylinderVolume);

          drpProduct.SelectedValue = Convert.ToString(vec.productID);


          txtVinnumber.Text = vec.vinNumber;
          txtRegnr.Text = vec.regnr;
          bdpRegdag.SelectedValue = vec.firstRegistrationDate;

          bdpStartDate.SelectedValue = vec.leaseStartDate;

      
            //hämta ut pricelistid
        //  flsfragusseEntities1 cEntity = new flsfragusseEntities1();
            var pricelist = from p in cEntity.tblPriceList
                      where p.priceListID == vec.priceListID
                      select p;

            foreach(var rPrice in pricelist)
            {
                drpServiceIntervall.SelectedValue = Convert.ToString(rPrice.ServiceIntervall);
                drpDuration.SelectedValue = Convert.ToString(rPrice.priceListDuration);
                drpDrivingDistance.SelectedValue=Convert.ToString(rPrice.priceListDistance);
            }
        //    vehicle.
        }

        
    }


    private void TerminateContract(int vehicleID)
    {
        flsfragusseEntities1 cEntity = new flsfragusseEntities1();

        var vehicle = from p in cEntity.tblVehicle
                      where p.vehicleID == vehicleID
                      select p;
        tblVehicle_change chg = new tblVehicle_change();

               
            foreach (var rec in vehicle)
            {
                chg.vehicleID = rec.vehicleID;
                chg.priceListID = rec.priceListID;
                chg.countryID = rec.countryID;
                chg.brandID = Convert.ToInt32(drpCarBrand.SelectedValue);
                chg.modelID = Convert.ToInt32(drpModell.SelectedValue);
                chg.isDieselcar = Convert.ToInt32(drpFueltype.SelectedValue);
                chg.cylinderVolume = Convert.ToInt32(drpCylinderVolume.SelectedValue);
                chg.regnr = txtRegnr.Text;
                chg.vinNumber = txtVinnumber.Text;
                if (bdpRegdag.SelectedDate.ToString() != "0001-01-01 00:00:00")
                    chg.firstRegistrationDate = bdpRegdag.SelectedDate;
                chg.leaseStartDate = bdpStartDate.SelectedDate;

                //produkten
                chg.productID = Convert.ToInt32(drpProduct.SelectedValue);
                // chg.priceListID = rec.priceListID;
                chg.userID = rec.userID;
                chg.partnerID = rec.partnerID;
                chg.dealerID = rec.vehicleID;

                chg.dealerEmployeeID = rec.dealerEmployeeID;
                chg.clientID = rec.clientID;
                chg.driverID = rec.driverID;
                chg.contractNumber = rec.contractNumber;
                chg.consumedDistance = rec.consumedDistance;
                chg.discountPercent = rec.discountPercent;
                chg.active = rec.active;
                chg.paymentMethod = rec.paymentMethod;
                chg.completed = rec.completed;
                chg.allowClaimWhenActive = rec.allowClaimWhenActive;
                chg.allowClaimWhenCanceled = rec.allowClaimWhenCanceled;

                chg.FromPartnerWeb = rec.FromPartnerWeb;
                chg.leaseEndDate = rec.leaseEndDate;
                chg.leaseStartKms = rec.leaseStartKms;
                chg.leaseEndKms = rec.leaseEndKms;
                chg.ExportToSantander = 0;
                chg.FromPartnerWeb = rec.FromPartnerWeb;
                chg.ExportOperation = "Cancellation";// rec.ExportOperation;
                chg.date = rec.date;
                chg.CreatedDate = DateTime.Now;

                //    chg.isDieselCar

            }

          
            //    chg.isDieselCar
        
        cEntity.tblVehicle_change.AddObject(chg);
        cEntity.SaveChanges();
    }
    private void SaveVechicle(int vehicleID,int productID, int pricelistduration, int priceListDistance, int fueltype, int cylinderVolume, int serviceintervall)
    {

         //<xs:enumeration value="NewContract" />
         //                       <xs:enumeration value="AddressModification" />
         //                       <xs:enumeration value="ContractModification" />
         //                       <xs:enumeration value="Cancellation" />

        //vi ska spara en ändringskopia isf.
        if (mode == Convert.ToInt32(modeUser.SALESMEN))
        {
            //hämta originalposten

            flsfragusseEntities1 cEntity = new flsfragusseEntities1();


           //först hämta ut den nya prislistan
            tblVehicle_change chg = new tblVehicle_change();

            var result = from p in cEntity.tblPriceList
                         orderby p.priceListCategory
                         where p.productID == productID && p.priceListDuration == pricelistduration && p.priceListDistance == priceListDistance && p.isDieselcar == fueltype && p.ServiceIntervall == serviceintervall && p.cylinderVolumeFrom <= cylinderVolume && p.cylinderVolumeTo >= cylinderVolume
                         select
                         new { price = p.price, ID = p.priceListID };
            //).Distinct();

            foreach (var rec in result)
            {
                //spara undran prislistid
                chg.priceListID = rec.ID;
            }

            var vehicle = from p in cEntity.tblVehicle
                          where p.vehicleID == vehicleID
                          select p;
           
         

            foreach(var rec in vehicle)
            {
                 chg.vehicleID = rec.vehicleID;
                 chg.countryID = rec.countryID;
                 chg.brandID = Convert.ToInt32(drpCarBrand.SelectedValue);
                 chg.modelID = Convert.ToInt32(drpModell.SelectedValue);
                chg.isDieselcar=Convert.ToInt32(drpFueltype.SelectedValue);
                chg.cylinderVolume = Convert.ToInt32(drpCylinderVolume.SelectedValue);
                chg.regnr = txtRegnr.Text;
                chg.vinNumber = txtVinnumber.Text;
                if(bdpRegdag.SelectedDate.ToString()!="0001-01-01 00:00:00")
                    chg.firstRegistrationDate = bdpRegdag.SelectedDate;
                chg.leaseStartDate = bdpStartDate.SelectedDate;

                //produkten
                chg.productID = Convert.ToInt32(drpProduct.SelectedValue); 
                // chg.priceListID = rec.priceListID;
                 chg.userID = rec.userID;
                 chg.partnerID = rec.partnerID;
                 chg.dealerID = rec.vehicleID;
               
                 chg.dealerEmployeeID = rec.dealerEmployeeID;
                 chg.clientID = rec.clientID;
                 chg.driverID = rec.driverID;
                 chg.contractNumber = rec.contractNumber;
                 chg.consumedDistance = rec.consumedDistance;
                 chg.discountPercent = rec.discountPercent;
                 chg.active = rec.active;
                 chg.paymentMethod = rec.paymentMethod;
                 chg.completed = rec.completed;
                 chg.allowClaimWhenActive = rec.allowClaimWhenActive;
                 chg.allowClaimWhenCanceled = rec.allowClaimWhenCanceled;
               
               
                 chg.leaseEndDate = rec.leaseEndDate;
                 chg.leaseStartKms = rec.leaseStartKms;
                 chg.leaseEndKms = rec.leaseEndKms;
                 chg.ExportToSantander = 0;
                 chg.FromPartnerWeb = rec.FromPartnerWeb;
                 chg.ExportOperation = "ContractModification";// rec.ExportOperation;
                 chg.date = rec.date;
                 chg.CreatedDate = DateTime.Now;
                     
             //    chg.isDieselCar

            }


            
           

           // tblvehiclechange.vehicleID=
            
           cEntity.tblVehicle_change.AddObject(chg);

           cEntity.SaveChanges();
        }

    }

    private void Fillcombos()
    {
        GetCouuntryCurrency();
        GetinvoiceFeeForPartner();
        filldata = true;
        FillBrand();
       

        FillbrandModel(Convert.ToInt32(drpCarBrand.SelectedValue));
        FillServiceIntervall(productid);
        FillCylinderVolume();
        FillProduct(productid);
        FillDuration(productid);
        FillDrivingDistance(productid, Convert.ToInt32(drpDuration.SelectedValue));

         FillFuelType();
         filldata = false;
         FillPaymentMethod(productid, Convert.ToInt32(drpDuration.SelectedValue), Convert.ToInt32(drpDrivingDistance.SelectedValue), Convert.ToInt32(drpFueltype.SelectedValue), Convert.ToInt32(drpCylinderVolume.SelectedValue), Convert.ToInt32(drpServiceIntervall.SelectedValue));


       
        // FillDealerEmployees(Convert.ToInt32(drpDealers.SelectedValue));


    
    }

    private void UpdatePrice()
    {
        if (!filldata)
            FillPaymentMethod(productid, Convert.ToInt32(drpDuration.SelectedValue), Convert.ToInt32(drpDrivingDistance.SelectedValue), Convert.ToInt32(drpFueltype.SelectedValue), Convert.ToInt32(drpCylinderVolume.SelectedValue), Convert.ToInt32(drpServiceIntervall.SelectedValue));

    }

    private void FillBrand()
    {
     //   Select brandID, brand From tblBrand where brandid=76 Order By brand
        //only nissan cars

        flsfragusseEntities1 cEntity = new flsfragusseEntities1();
        drpCarBrand.DataSource = from p in cEntity.tblBrand
                                 orderby p.brand 
                                 where p.brandID==76
                                 select
                                 new { Name = p.brand, ID = p.brandID };


        drpCarBrand.DataTextField = "Name";
        drpCarBrand.DataValueField = "ID";
        drpCarBrand.DataBind();
    }


   
    //private void FillCylinderVolume()
    //{
    //    List<Cylindervolume> lst = new List<Cylindervolume>();
    //    for (int i = 1000; i < 8100; i = i + 100)
    //    {
    //        lst.Add(new Cylindervolume { Name = i });
    //    }

    //    drpCylinderVolume.DataSource = lst;
    //    drpCylinderVolume.DataTextField = "Name";

    //    drpCylinderVolume.DataBind();

    //}
    public class Fueltype
    {
        public string Name { get; set; }
        public int Value { get; set; }
    }

    private void FillFuelType()
    {
        List<Fueltype> lst = new List<Fueltype>();
       
        lst.Add(new Fueltype { Name ="Diesel", Value=1,  });
        lst.Add(new Fueltype { Name = "Bensin", Value =2, });
       
        drpFueltype.DataSource = lst;
        drpFueltype.DataTextField = "Name";
        drpFueltype.DataValueField = "Value";

        drpFueltype.DataBind();

    }
    private void FillbrandModel(int brandid)
    {
        flsfragusseEntities1 cEntity = new flsfragusseEntities1();
        drpModell.DataSource = from p in cEntity.tblModel
                                 orderby p.model
                                 where p.brandID == brandid
                                 select
                                 new { Name = p.model, ID = p.modelID };


        drpModell.DataTextField = "Name";
        drpModell.DataValueField = "ID";
        drpModell.DataBind();
    }

    //SELECT     distinct ServiceIntervall FROM   tblPriceList WHERE     (productID = 17)"

    private void FillServiceIntervall(int productID)
    {
        flsfragusseEntities1 cEntity = new flsfragusseEntities1();
        drpServiceIntervall.DataSource = (from p in cEntity.tblPriceList
                               orderby p.ServiceIntervall
                                          where p.productID == productID
                               select 
                               new { Name = p.ServiceIntervall }).Distinct();


        drpServiceIntervall.DataTextField = "Name";
        drpServiceIntervall.DataValueField = "Name";
        drpServiceIntervall.DataBind();
    }

    private void FillProduct(int productID)
    {
     //   Select productID, product From tblProduct Where partnerID

        
        flsfragusseEntities1 cEntity = new flsfragusseEntities1();
        drpProduct.DataSource = (from p in cEntity.tblProduct
                                          orderby p.product
                                          where p.productID == productID
                                          select
                                          new { Name = p.product,ID=p.productID  });


        drpProduct.DataTextField = "Name";
        drpProduct.DataValueField = "ID";
        drpProduct.DataBind();
    }

    //     Select priceListDuration From tblPriceList Where productID = " & productID & " GROUP BY priceListDuration ORDER BY priceListDuration

    private void FillDuration(int productID)
    {
        flsfragusseEntities1 cEntity = new flsfragusseEntities1();
        drpDuration.DataSource = (from p in cEntity.tblPriceList
                            
                                
                                 orderby p.priceListDuration
                                 where p.productID == productID
                                 select
                                 new { Name = p.priceListDuration, ID = p.priceListDuration }).Distinct();


        drpDuration.DataTextField = "Name";
        drpDuration.DataValueField = "ID";
        drpDuration.DataBind();
    }

    private void FillDrivingDistance(int productID, int pricelistduration)
    {

        //  RecSet = Conn.Execute("Select priceListDistance From tblPriceList Where productID = " & productID & " And priceListDuration = " & priceListDuration & " GROUP BY priceListDistance ORDER BY priceListDistance")
      
        flsfragusseEntities1 cEntity = new flsfragusseEntities1();

        drpDrivingDistance.DataSource = (from p in cEntity.tblPriceList
                            
                                
                                 orderby p.priceListDuration
                                 where p.productID == productID && p.priceListDuration==pricelistduration
                                 select
                                 new { Name = p.priceListDistance, ID = p.priceListDistance }).Distinct();

        drpDrivingDistance.DataTextField = "Name";
        drpDrivingDistance.DataValueField = "ID";
        drpDrivingDistance.DataBind();
    }
        

         

    private void FillPaymentMethod(int productID, int pricelistduration,int priceListDistance,int fueltype,int cylinderVolume,int serviceintervall)
    {
        //uppdatera priser om inte combosar laddar


        
            GetCouuntryCurrency();
            GetinvoiceFeeForPartner();
            //     sql = "Select priceListID, priceListCategory, price From tblPriceList Where productID = " & productID & " And priceListDuration = " & priceListDuration & " And priceListDistance = " & priceListDistance & " And isDieselcar = " & fueltype & " And cylinderVolumeFrom <= " & cylinderVolume & " And cylinderVolumeTo >= " & cylinderVolume & " And ServiceIntervall = " & serviceintervall & " ORDER BY priceListCategory"



            //  RecSet = Conn.Execute("Select priceListDistance From tblPriceList Where productID = " & productID & " And priceListDuration = " & priceListDuration & " GROUP BY priceListDistance ORDER BY priceListDistance")

            flsfragusseEntities1 cEntity = new flsfragusseEntities1();

            var result = from p in cEntity.tblPriceList
                         orderby p.priceListCategory
                         where p.productID == productID && p.priceListDuration == pricelistduration && p.priceListDistance == priceListDistance && p.isDieselcar == fueltype && p.ServiceIntervall == serviceintervall && p.cylinderVolumeFrom <= cylinderVolume && p.cylinderVolumeTo >= cylinderVolume
                         select
                         new { price = p.price, ID = p.priceListDistance };
                          //).Distinct();

            foreach (var rec in result)
            {
                System.Diagnostics.Debug.WriteLine("productid: {0}, pricelistduration: {1}, pricelistdistance {2}, isdieselcar {3}, cylindervolume {4}, serviceintervall {5}",
                    productid.ToString(), pricelistduration.ToString(), priceListDistance.ToString(), fueltype.ToString(), cylinderVolume.ToString(), serviceintervall.ToString());

                lblBetalningsmetod.Text = string.Format("Månad- {0} {1} + {2} {3} / Månad", pricelistduration, rec.price, invoiceFee, countryCurrency);
            }

       
        
      //  drpPriceCategory.DataTextField = "Name";
      //  drpPriceCategory.DataValueField = "ID";
      //  drpPriceCategory.DataBind();
    }

   // private void FillPaymentMethod(int pricelistduration,


    //montlyprice price från price from tvlpricelist

    //invoice fee
    //  Conn.Execute("Select invoiceFee From tblPartner Where partnerID = " & partnerID & "")

       //   Response.Write("<option value='" & priceListDuration & "'> kuukausittain- " & monthlyPrice & " + " & FormatNumber(CDbl(invoiceFee), 5) & " " & countryCurrency & " / kuukausittain ")
       

   // Select priceListDistance From tblPriceList Where productID = " & productID & " And priceListDuration = " & priceListDuration & " GROUP BY priceListDistance ORDER BY priceListDistance"



    public class Cylindervolume
    {
        public int Name { get; set; }
    
    }
    private void FillCylinderVolume()
    {
        List<Cylindervolume> lst = new List<Cylindervolume>();
        for (int i = 1000; i < 8100; i=i+100)
        {
            lst.Add(new Cylindervolume { Name = i});
            

          
        }

        drpCylinderVolume.DataSource = lst;
        drpCylinderVolume.DataTextField = "Name";

        drpCylinderVolume.DataBind();
       
    }


    private void FillDealerEmployees(int dealerid)
    {

        flsfragusseEntities1 cEntity = new flsfragusseEntities1();


        //3 är nissan

        //    drpSalesMen.DataSource = from p in cEntity.tblDealerEmployee
        //                            orderby p.dealerEmployee
        //                            where p.dealerID == dealerid
        //                            select
        //                                new { Name = p.dealerEmployee, ID = p.dealerEmployeeID };


        //    drpSalesMen.DataTextField = "Name";
        //    drpSalesMen.DataValueField = "ID";
        //    drpSalesMen.DataBind();
        //}
    }
    private void FillDealers()
    {
        flsfragusseEntities1 cEntity = new flsfragusseEntities1();


        ////3 är nissan
        //drpDealers.DataSource = from p in cEntity.tblDealer
        //                        orderby p.dealer
        //                        where p.partnerID == 3
        //                        select
        //                            new { Name = p.dealer, ID = p.dealerID };


        //drpDealers.DataTextField = "Name";
        //drpDealers.DataValueField = "ID";
        //drpDealers.DataBind();
    }
    
    
       
       

     
    

    private void disableTextboxesInBPD(BDPLite BDP)
    {
        ControlCollection controls = BDP.Controls;
        foreach (Control ctrl in controls)
        {
            if (ctrl is TextBox)
            {
                TextBox txtBox = (TextBox)ctrl;

                txtBox.ReadOnly = true;

            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {


        disableTextboxesInBPD(bdpRegdag);
        //disableTextboxesInBPD(bdpContractStopDate);
        //disableTextboxesInBPD(bdpSignDate);
        //disableTextboxesInBPD(bdpDueDate);
        //disableTextboxesInBPD(bdpSignDate);

     //   LoadChangesAndCompare(4693);


    }
    protected void btnapprove_Click(object sender, EventArgs e)
    {
        //då sparar vi posten.

    }
    protected void drpDealers_SelectedIndexChanged(object sender, EventArgs e)
    {
        //if(!filldata)
        //   FillDealerEmployees(Convert.ToInt32(drpDealers.SelectedValue));
    }
    protected void drpFueltype_SelectedIndexChanged(object sender, EventArgs e)
    {
        if(!filldata)
            UpdatePrice();
    }
    protected void drpServiceIntervall_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (!filldata)
            UpdatePrice();
    }
    protected void drpCylinderVolume_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (!filldata)
            UpdatePrice();
    }
    protected void drpProduct_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (!filldata)
        {
            UpdatePrice();
            FillDuration(productid);
        }
    }
    protected void drpDuration_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (!filldata)
        {
            FillDrivingDistance(productid, Convert.ToInt32(drpDuration.SelectedValue));
            UpdatePrice();

        }
    }
    protected void drpDrivingDistance_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (!filldata)
            UpdatePrice();
    }
    protected void drpPriceCategory_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (!filldata)
            UpdatePrice();
    }
    protected void drpCarBrand_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (!filldata)
            FillbrandModel(Convert.ToInt32(drpCarBrand.SelectedValue));
    }
    protected void btnApprove_Click(object sender, EventArgs e)
    {

    }
    protected void btnDissaprove_Click(object sender, EventArgs e)
    {

    }
    protected void btnSpara_Click(object sender, EventArgs e)
    {

        //först hämta ut dem nya värdena

       
        SaveVechicle(Convert.ToInt32(lblQuerystring.Text), Convert.ToInt32(drpProduct.SelectedValue),Convert.ToInt32(drpDuration.SelectedValue),Convert.ToInt32(drpDrivingDistance.SelectedValue),
            Convert.ToInt32(drpFueltype.SelectedValue),Convert.ToInt32(drpCylinderVolume.SelectedValue),Convert.ToInt32(drpServiceIntervall.SelectedValue));
        DisplaySaveModified();
   //     Response.Redirect(lblreferer.Text);
       
    }

    protected void DisplaySaveModified()
    {
        lblresult.Text = "Aftaleet her blevet ændret";
        lblresult.Visible = true;
        Response.AddHeader("Refresh", string.Format("2;URL={0}", lblreferer.Text));
    }

    protected void DisplayTerminated()
    {
        lblresult.Text = "Aftaleet er blevet ændret";
        lblresult.Visible = true;
        Response.AddHeader("Refresh", string.Format("2;URL={0}", lblreferer.Text));
    }

    protected void btnTerminate_Click(object sender, EventArgs e)
    {
        TerminateContract(Convert.ToInt32(lblQuerystring.Text));
        DisplayTerminated();
    }
}